import heapq
class Solution(object):
    def minStoneSum(self, piles, k):
        piles = [-p for p in piles]
        heapq.heapify(piles)
        c = 0
        while c < k:
            c += 1
            node = heapq.heappop(piles)
            node = (- node + 1) // 2
            heapq.heappush(piles, - node)
        return - sum(piles)
